package com.jysz.certificate.persistence.model.mf;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.jysz.certificate.persistence.enums.mf.BillStatus;
import com.jysz.certificate.persistence.model.system.User;
import com.jysz.webcore.ssh.entity.AbstractBaseEntity;

/**
 * 发票申请单
 * @author xuxiaolong
 */
@Entity
@Table(name = "mf_bill_apply_")
@org.hibernate.annotations.Entity
public class BillApply extends AbstractBaseEntity<Long> {

	private static final long serialVersionUID = 8840289259694398289L;
	
	/** 申请人*/
	private User applyUser;
	
	/** 申请批次号*/
	private String applyNum;
	
	/** 申请时间*/
	private Date applyDate;
	
	/** 申请单状态*/
	private BillStatus status;
	
	/** 是否是开票店
	 * true 店
	 * false 金融机构
	 * */
	private Boolean shopFlag;
	
	/** 申请单所包含的发票*/
	private List<Bill> bills;

	@ManyToOne(targetEntity=User.class,cascade=CascadeType.REFRESH)
	@JoinColumn(name="_apply_user", insertable=true, updatable=true,columnDefinition="bigint(20)")
	public User getApplyUser() {
		return applyUser;
	}

	public void setApplyUser(User applyUser) {
		this.applyUser = applyUser;
	}

	@Column(name = "_apply_num", nullable = true,columnDefinition="varchar(255)")
	public String getApplyNum() {
		return applyNum;
	}

	public void setApplyNum(String applyNum) {
		this.applyNum = applyNum;
	}
	
	@Column(name = "_apply_date", nullable = true)
	public Date getApplyDate() {
		return applyDate;
	}

	public void setApplyDate(Date applyDate) {
		this.applyDate = applyDate;
	}

	@Column(name = "_status", nullable = false,columnDefinition="int(11)")
	public BillStatus getStatus() {
		return status;
	}

	public void setStatus(BillStatus status) {
		this.status = status;
	}

	@OneToMany(targetEntity = Bill.class,cascade = { CascadeType.ALL }, mappedBy = "billApply")  
	@Fetch(FetchMode.SUBSELECT)
	public List<Bill> getBills() {
		return bills;
	}

	public void setBills(List<Bill> bills) {
		this.bills = bills;
	}

	@Column(name = "_shop_flag", nullable = false,columnDefinition="bit(1)")
	public Boolean getShopFlag() {
		return shopFlag;
	}

	public void setShopFlag(Boolean shopFlag) {
		this.shopFlag = shopFlag;
	}

}
